package edu.whu.demo.service.impl;

import com.baidu.aip.contentcensor.AipContentCensor;
import com.baidu.aip.contentcensor.EImgType;
import org.json.JSONObject;
import org.springframework.stereotype.Service;

@Service
public class AuditService {
    //设置APPID/AK/SK
    private static final String APP_ID = "29011087";
    private static final String API_KEY = "aPTboYpXU9HhnHtVyqXxg6bV";
    private static final String SECRET_KEY = "AfqfTHj9DZ3GbuiuoyxeEVHT7N5sPdYh";

    private final AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);

    public boolean pictureAudit(String path){
        JSONObject response = client.imageCensorUserDefined(path, EImgType.FILE, null);   // 本地图片路径
//        JSONObject response = client.imageCensorUserDefined(path, EImgType.URL, null);         // 网络图片
        System.out.println(response.toString());
        if(response.get("conclusion").equals("合规")){
            return true;
        }
        else return false;
    }

    public boolean textAudit(String text){
        JSONObject response = client.textCensorUserDefined(text);
        System.out.println(response.toString());
        if(response.get("conclusion").equals("合规")){
            return true;
        }
        else return false;
    }

}
